<template>
    <div class="app-download-warp">
        <img src="http://img.uuuda.com/udaWeapp2.0/icon/down/app_down_logo.png" class="down-bg"/>
        <!--<div id="app-to-wx"></div>-->
        <wx-open-launch-weapp
                    class="openweapp"
                    id="launch-btn"
                    username="gh_b691189a3020"
                    path="pages/homeIndex/homeIndex.html"
                  >
            <script type="text/wxtag-template">
                <button class="open-launch-weapp-btn" style="background-color: transparent;border: none;color:#FDE6B0;font-size:12px;">去小程序</button>
            </script>


        </wx-open-launch-weapp>



    </div>


</template>

<script>
let axios = require("axios");
// import wx from "weixin-js-sdk";

export default {
    data() {
        return {
          test:''

        };
    },
    beforeCreate(){






},
    created() {

        let self = this;
        // self.initWx();
        // alert(location.href.split('#')[0])
        let wxJs = document.createElement('script');
        wxJs.src = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
        document.head.appendChild(wxJs);
        wxJs.onload = function () {
            self.initWx()

        };
    },
    mounted(){
        let self = this;
        let script = document.createElement('script')
        script.type = 'text/wxtag-template'
        script.text = ` <button class="btn" style="padding: 12px">打开小程序</button>`
        let html = `<wx-open-launch-weapp id="launch-btn" style="width:100%;display:block;height:70px;" username="gh_b691189a3020" path="pages/homeIndex/homeIndex.html">${script.outerHTML}</wx-open-launch-weapp>`
        // let html = `<wx-open-launch-weapp id="launch-btn" username="gh_b691189a3020" path="pages/homeIndex/homeIndex.html">
        //                     <template>
        //                         <style>.btn {padding: 18px}</style>
        //                         <button class="btn">打开小程序</button>
        //                     </template>
        //                 </wx-open-launch-weapp>`
        // document.getElementById('app-to-wx').innerHTML = html;
        var btn = document.getElementById("launch-btn");
        btn.addEventListener("launch", function (e) {
            console.log("success");
        });
        btn.addEventListener("error", function (e) {
            alert("小程序打开失败");
            console.log("fail", e.detail);
        });
    },

    watch:{


    },
    methods: {
       initWx:function () {
           let self =this;

           axios({
               method: "post",
               url: "/api/wx/jump",
               params: {

               }
           }).then(function(res) {
               let data = res.data;
               console.log(data.appId)

                   wx.config({
                       debug: true,// 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                       appId: data.appId,         // 必填，公众号的唯一标识，填自己的！
                       timestamp:data.timestamp, // 必填，生成签名的时间戳，刚才接口拿到的数据
                       nonceStr: data.nonceStr,   // 必填，生成签名的随机串
                       signature:data.signature, // 必填，签名，见附录1
                       jsApiList: [
                           'onMenuShareTimeline'
                       ],
                       openTagList: ["wx-open-launch-weapp"] // 跳转小程序时必填
                   })
                   wx.ready(function (res) {
                       console.log("成功")
                       console.log(res)
                       // wx.miniProgram.navigateTo({url:'/pages/homeIndex/homeIndex'})

                   })
                   wx.error(function (res) {
                       // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名
                       console.log("失败")
                       console.log(res)

                   });

           });
       }


    },

}

</script>

<style>
    .app-download-warp{
        position: absolute;
        width: 100%;
        height: 100%;
        background: white;
    }
    .down-bg{
        position: relative;
        width: 100%;
    }








</style>
